﻿bob.ns.setNs('bob.serialization', {

    //TODO: implement object-oriented serialization mechanism.

    objectToString: function (obj, bQuote) {
        var objType = typeof (obj);

        if (bob.utils.isUndefinedOrNull(obj)
            || (bob.collections.extensions.indexOf.call(['number', 'boolean'], true, objType) >= 0)) {
            return '' + obj;
        }
        else if ((objType === 'string')
            || bob.utils.isDate(obj)) {
            return bQuote ? bob.utils.quote(obj) : '' + obj;
        }
        else if (objType === 'function') {
            return 'function() { }';
        }
        else if (bob.utils.isArray(obj)) {
            var strResult = '[ ';
            for (var i = 0; i < obj.length; i++) {

                if (i > 0) {
                    strResult += ', ';
                }

                strResult += bob.serialization.objectToString(obj[i], true);
            }
            strResult += ' ]';
            return strResult;
        }
        else { //object
            var strResult = '{ ';
            var index = 0;
            for (var member in obj) {

                if (index++ > 0) {
                    strResult += ', ';
                }

                strResult += bob.utils.quote(member) + ': ';

                strResult += bob.serialization.objectToString(obj[member], true);
            }
            strResult += ' }';
            return strResult;
        }
    }

});
